﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Images.ascx.cs" Inherits="Sites_Vigor_Webparts_Common_Images" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="NTTHAO.Web.BL.CommonPage" %>
<%
if (_Menu != null)
{ %>
<h1 style="display: none;"><%=Server.HtmlEncode(_Menu.Text)%></h1>
<div class="image-list"><%
    if (_List != null)
    {
        //string imagePath = "/" + Constant.UPLOAD_FILE_PATH + "commonpage/";
        for (int i = 0; i < _List.Rows.Count; i++)
        {
            bool first = (i == 0 && _PageNo == 1);
            DataRow row = _List.Rows[i];
            
            int id = (int)row[CommonAlbum.ID__COLUMN_NAME];
            string menuID = row[CommonAlbum.MENUID__COLUMN_NAME].ToString();
            string header = row[CommonAlbum.ALBUMNAME__COLUMN_NAME].ToString();
            string imagePath = row[CommonAlbum.IMAGEPATH__COLUMN_NAME].ToString();
            string image = first ? row[CommonAlbum.IMAGE__COLUMN_NAME].ToString() : row[CommonAlbum.MINIIMAGE__COLUMN_NAME].ToString();
            string date = ((DateTime)row[CommonAlbum.INSERTDATE__COLUMN_NAME]).ToString("dd/MM/yyyy");
%>
    <div class="item <%=first? "item-first" : "" %>"><%if (image.Length > 0) { %>
        <div class="img">
            <a href="#" class="gallery-view" galleryid="<%=id.ToString("0") %>"><img src="/<%=imagePath + image %>" alt="<%=header.Replace("\"", "'") %>" title="<%=header.Replace("\"", "'") %>" /></a>
        </div>
        <div class="info">
            <h3><a href="#" class="gallery-view" galleryid="<%=id.ToString("0") %>"><%=Server.HtmlEncode(header) %></a></h3>
            <div class="date">Ngày đăng: <span><%=date %></span></div>
        </div>
        <div class="di-no" id="gallery_<%=id.ToString("0") %>">
<%
    DataTable tb = CommonImage.GetImages(id, 1);
    if (tb != null && tb.Rows.Count > 0)
        for (int j = 0; j < tb.Rows.Count; j++)
        {
            DataRow rowj = tb.Rows[j];
            string imageFilej = rowj[CommonImage.IMAGEFILENAME__COLUMN_NAME].ToString();
            string imageNamej = rowj[CommonImage.IMAGENAME__COLUMN_NAME].ToString().Replace("\"", "'");
            string miniImageFilej = "Mini_" + imageFilej;
%><a <%=j == 0 ? "id=\"thumb" + (i+1).ToString("0") + "\"" : "" %> rel="gallery_<%=id.ToString("0") %>" href="/<%=imagePath + imageFilej %>"><img src="/<%=imagePath + miniImageFilej %>" alt="<%=imageNamej %>" /></a>
<%
        }
%>
        </div>
        <%} %>
    </div><%
        }
    }
%>
<script type="text/javascript">
    $("a.gallery-view").click(function(){ 
        var me = $(this);
        if (me.attr('galleryid') == null) return true;
        var items = $('#gallery_' + me.attr('galleryid') + ' a');
        items.fancybox();//.open();
        items.eq(0).trigger("click");
        return false;
	});
</script>
</div><%
          if (_PageCount > 0 && _TotalItem > 0) 
{ %>
<div class="boxPaging oh">
    <div class="pagenum">
        <ul>
            <li><a class="first" href="<%=this._BaseURL + "page/1/" %>">&nbsp;&nbsp;</a></li>
            <li><a class="pre" href="<%=this._BaseURL + "page/" + (this._PageNo <= 1 ? 1 : (this._PageNo - 1)) + "/" %>">&nbsp;&nbsp;</a></li>
            <%
                int startPage = _PageNo - 4;
                if (startPage > _PageCount - 9)
                {
                    startPage = _PageCount - 9;
                }
                if (startPage < 1)
                {
                    startPage = 1;
                }
                for (int i = startPage; i <= _PageCount && i < (startPage + 10); i++) 
                {
            %>
            <li <%=(i == _PageNo ? "class=\"selected\"" : "") %>><a href="<%=this._BaseURL + "page/" + i.ToString() + "/" %>"><%=i %></a></li>
            <%   
                }
            %>
            <li><a class="next" href="<%=this._BaseURL + "page/" + (this._PageNo >= this._PageCount ? this._PageCount : (this._PageNo + 1)) + "/" %>">&nbsp;&nbsp;</a></li>
            <li><a class="last" href="<%=this._BaseURL + "page/" + this._PageCount.ToString() + "/" %>">&nbsp;&nbsp;</a></li>
        </ul>
    </div>
</div>
<%
    } %>
<%
} %>
